const db=wx.cloud.database()

Page({

    /**
     * 页面的初始数据
     */
    data: {
      value1:"选择搜索内容",
        option1: [
           // { text: '志愿者ID', value: 0 },
            { text: '项目ID', value: 0 },
          //  { text: '动态', value: },
          { text: '项目名称', value: 1 },
            {text:"团队ID",value:2},
           
            {text:"团队名称",value:3},
            {text:"成员姓名",value:4},
            {text:"成员ID",value:5}
          ],
       searchKey:'',
       historySearch:[],
       hotSearch:[],
       searchTarget:"",
       searchRes:"",
    },
    gerKey(e){
       console.log(e.detail)
       this.setData({
        searchTarget:e.detail,
        searchRes:null
       })
      
    },
    getsearchKey(e){
       console.log(e.detail.value)
       this.setData({
         searchKey:e.detail.value
       })
    },
    goteamDetail(e)
    {
      console.log(e)
      wx.navigateTo({
        url: '../project_all/teamDetail/teamDetail?id='+e.currentTarget.dataset.id,
      })
    },
    goProjectDetail(e)
    {
      wx.navigateTo({
        url: '../project_all/projectDetail/projectDetail?id='+e.currentTarget.dataset.id,
      })
      
    },
    getcontent(){
     // this.updataHistorySearch(this.data.searchKey)
      if(this.data.searchTarget==0){
        wx.cloud.callFunction({
          name:"search",
          data:{
            action:"projectID",
            ID:this.data.searchKey
          }
        })
        .then(res=>{
          console.log("查询项目ID成功",res)
          if(res.result.data=="")
          {
          this.setData({
            searchRes:null
          })
          }
          else{
              this.setData({
                searchRes:res.result.data
              })
          }
        })
      }
      if(this.data.searchTarget==1){
        wx.cloud.callFunction({
          name:"search",
          data:{
            action:"projectName",
            projectName:this.data.searchKey
          }
        })
        .then(res=>{
          console.log("查询项目名称成功",res)
          if(res.result.data=="")
          {
          this.setData({
            searchRes:null
          })
          }
          else{
              this.setData({
                searchRes:res.result.data
              })
          }
        })
      }
      if(this.data.searchTarget==2){
        wx.cloud.callFunction({
          name:"search",
          data:{
            action:"teamID",
            teamID:this.data.searchKey
          }
        })
        .then(res=>{
          console.log("查询团队ID成功",res)
          if(res.result.data=="")
          {
          this.setData({
            searchRes:null
          })
          }
          else{
              this.setData({
                searchRes:res.result.data
              })
          }
        })
      }
      if(this.data.searchTarget==3)
      {
        wx.cloud.callFunction({
          name:"search",
          data:{
            action:"teamName",
            teamName:this.data.searchKey
          }
          
        })
        .then(res=>{
          console.log("查询成功团队名称成功",res)
          if(res.result.data=="")
          {
          this.setData({
            searchRes:null
          })
          }
          else{
              this.setData({
                searchRes:res.result.data
              })
          }
        })
      }   
    
   
    },
    onLoad: function (options) {
       console.log("从首页传来的SearchKey",options.searchKey)
       this.setData({
        searchKey:options.searchKey
       })
      // if(options.searchKey!=null)
      // this.updataHistorySearch(options.searchKey)
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})